class Solution(object):
    def longestConsecutive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        l = len(nums)
        if l==0:
            return 0
        d = {}
        for i in nums:
            d[i] = 1
        res = 0
        for i in nums:
            if i-1 not in d:
                c = 1
                y = i+1
                while y in d:
                    c+=1
                    y+=1
                res = max(res,c)
        return res